

# Emitter

<div class="api-docs__separator" data-reactroot="">

---

</div><div class="api-docs__import" data-reactroot="">

```ts
import { Emitter } from "@hyper-fetch/sockets"
```

</div><div class="api-docs__section">

## Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:8](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L8)

</p><div class="api-docs__section">

## Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="socket"><td class="api-docs__param-name required">

### socket 

`Required`

</td><td class="api-docs__param-type">

`Socket<AdapterType>`

</td></tr><tr param-data="emitterOptions"><td class="api-docs__param-name required">

### emitterOptions 

`Required`

</td><td class="api-docs__param-type">

`EmitterOptionsType<Endpoint, AdapterType>`

</td></tr><tr param-data="json"><td class="api-docs__param-name optional">

### json 

`Optional`

</td><td class="api-docs__param-type">

`Partial<Emitter<Payload, Response, Endpoint, AdapterType, MappedData, false, false>>`

</td></tr><tr param-data="dataMapper"><td class="api-docs__param-name optional">

### dataMapper 

`Optional`

</td><td class="api-docs__param-type">

`(data: Payload) => MappedData`

</td></tr></tbody></table></div><div class="api-docs__section">

## Properties

</div><div class="api-docs__properties"><div class="api-docs__property" property-data="connections"><h3 class="api-docs__name">

### `connections`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:22](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L22)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Set<ConnectMethodType<AdapterType, Response>>
```

</div><hr/></div><div class="api-docs__property" property-data="data"><h3 class="api-docs__name">

### `data`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:20](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L20)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Payload
```

</div><hr/></div><div class="api-docs__property" property-data="emitterOptions"><h3 class="api-docs__name">

### `emitterOptions`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:26](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L26)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
EmitterOptionsType<Endpoint, AdapterType>
```

</div><hr/></div><div class="api-docs__property" property-data="endpoint"><h3 class="api-docs__name">

### `endpoint`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:17](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L17)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Endpoint
```

</div><hr/></div><div class="api-docs__property" property-data="options"><h3 class="api-docs__name">

### `options`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:21](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L21)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
ExtractEmitterOptionsType<AdapterType>
```

</div><hr/></div><div class="api-docs__property" property-data="params"><h3 class="api-docs__name">

### `params`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:18](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L18)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
ParamsType
```

</div><hr/></div><div class="api-docs__property" property-data="socket"><h3 class="api-docs__name">

### `socket`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:25](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L25)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
Socket<AdapterType>
```

</div><hr/></div><div class="api-docs__property" property-data="timeout"><h3 class="api-docs__name">

### `timeout`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:19](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L19)

</p><div class="api-docs__section">

#### Type

</div><div class="api-docs__property-type">

```ts
number
```

</div><hr/></div></div><div class="api-docs__section">

## Methods

</div><div class="api-docs__methods"><div class="api-docs__method" method-data="dataMapper"><h3 class="api-docs__name">

### `dataMapper()`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:28](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L28)

</p><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
(data: Payload) => MappedData
```

</div><hr/></div><div class="api-docs__method" method-data="emit"><h3 class="api-docs__name">

### `emit()`

</h3><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:127](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L127)

</p><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
ExtractEmitterHasDataType<Emitter> extends false ? (options: [object Object]) => string : (ExtractRouteParams<ExtractEmitterEndpointType<Emitter>> extends NegativeTypes ? (options?: [object Object]) => string : (ExtractEmitterHasParamsType<Emitter> extends false ? (options: [object Object]) => string : (options?: [object Object]) => string))
```

</div><hr/></div><div class="api-docs__method" method-data="clone"><h3 class="api-docs__name">

### `clone()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
clone<NewPayload, MapperData, Params, Data>(options, mapper)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:83](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L83)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="options"><td class="api-docs__param-name optional">

#### options 

`Optional`

</td><td class="api-docs__param-type">

`Partial<EmitterOptionsType<Endpoint, AdapterType>> & { data?: NewPayload; params?: ParamsType }`

</td></tr><tr param-data="mapper"><td class="api-docs__param-name optional">

#### mapper 

`Optional`

</td><td class="api-docs__param-type">

`(data: NewPayload) => MapperData`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<NewPayload, Response, Endpoint, AdapterType, MapperData, Params, Data>
```

</div><hr/></div><div class="api-docs__method" method-data="getAck"><h3 class="api-docs__name">

### `getAck()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
getAck(ack)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:112](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L112)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="ack"><td class="api-docs__param-name optional">

#### ack 

`Optional`

</td><td class="api-docs__param-type">

`EmitterAcknowledgeType<any, AdapterType>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
(response: [object Object]) => void
```

</div><hr/></div><div class="api-docs__method" method-data="onData"><h3 class="api-docs__name">

### `onData()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
onData(callback)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">

Attach global logic to the received events

</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:66](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L66)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="callback"><td class="api-docs__param-name required">

#### callback 

`Required`

</td><td class="api-docs__param-type">

`ConnectMethodType<AdapterType, Response>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<Payload, Response, Endpoint, AdapterType, MappedData, HasParams, HasData>
```

</div><hr/></div><div class="api-docs__method" method-data="setData"><h3 class="api-docs__name">

### `setData()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setData(data)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:47](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L47)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="data"><td class="api-docs__param-name required">

#### data 

`Required`

</td><td class="api-docs__param-type">

`Payload`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<MappedData, Response, Endpoint, AdapterType, MappedData, HasParams, true>
```

</div><hr/></div><div class="api-docs__method" method-data="setDataMapper"><h3 class="api-docs__name">

### `setDataMapper()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setDataMapper<MapperData>(mapper)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:54](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L54)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="mapper"><td class="api-docs__param-name required">

#### mapper 

`Required`

</td><td class="api-docs__param-type">

`(data: Payload) => MapperData`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<Payload, Response, Endpoint, AdapterType, MapperData, HasParams, HasData>
```

</div><hr/></div><div class="api-docs__method" method-data="setOptions"><h3 class="api-docs__name">

### `setOptions()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setOptions(options)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:39](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L39)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="options"><td class="api-docs__param-name required">

#### options 

`Required`

</td><td class="api-docs__param-type">

`ExtractEmitterOptionsType<AdapterType>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<Payload, Response, Endpoint, AdapterType, MappedData, HasParams, HasData>
```

</div><hr/></div><div class="api-docs__method" method-data="setParams"><h3 class="api-docs__name">

### `setParams()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setParams(params)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:58](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L58)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="params"><td class="api-docs__param-name required">

#### params 

`Required`

</td><td class="api-docs__param-type">

`ExtractRouteParams<Endpoint>`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<Payload, Response, Endpoint, AdapterType, MappedData, true, HasData>
```

</div><hr/></div><div class="api-docs__method" method-data="setTimeout"><h3 class="api-docs__name">

### `setTimeout()`

</h3><div class="api-docs__section">

#### Preview

</div><div class="api-docs__preview fn">

```ts
setTimeout(timeout)
```

</div><div class="api-docs__section">

#### Description

</div><div class="api-docs__description"><span class="api-docs__do-not-parse">



</span></div><p class="api-docs__definition">

Defined in [emitter/emitter.ts:43](https://github.com/BetterTyped/hyper-fetch/blob/cc329b91/packages/sockets/src/emitter/emitter.ts#L43)

</p><div class="api-docs__section">

#### Parameters

</div><div class="api-docs__parameters"><table><thead><tr><th>Name</th><th>Details</th></tr></thead><tbody><tr param-data="timeout"><td class="api-docs__param-name required">

#### timeout 

`Required`

</td><td class="api-docs__param-type">

`number`

</td></tr></tbody></table></div><div class="api-docs__section">

#### Return

</div><div class="api-docs__returns">

```ts
Emitter<Payload, Response, Endpoint, AdapterType, MappedData, HasParams, HasData>
```

</div><hr/></div></div>